package _1_leetcode_1_20._09回文数;

public class ExecuteMain {

    public static void main(String[] args) {
        System.out.println(isPalindrome(-123));
        System.out.println(isPalindrome(121));
        System.out.println(isPalindrome(123));
    }

    public static boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        if (x < 10) {
            return true;
        }
        int tmp = reverse(x);
        if (tmp == x) {
            return true;
        } else {
            return false;
        }
    }

    public static int reverse(int x) {
        long n = 0;
        while (x != 0) {
            n = n * 10 + x % 10;
            x = x / 10;
        }
        return (int) n == n ? (int) n : 0;
    }

}
